package level.editor.control.collision;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.WindowFocusListener;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;

import level.editor.control.Control;
import level.editor.control.main.MainTabbed;
import level.editor.view.Window;
import level.editor.view.action.ActionConstants;

public class CollisionControl extends Control
{

	public CollisionControl(MainTabbed tabbed)
	{
		super(tabbed);
		init();
	}

	private void init()
	{
		setName("Collision Tool");
		setIcon(new ImageIcon(ActionConstants.ICON_DIR + "collision.png"));
		setMinimumSize(new Dimension(200, 100));
		initHandler();
		initCollisionSelect();
		initOptions();
	}

	private void initHandler()
	{
		handler = new CollisionHandler(this);
		((Window) tabbed.getTopLevelAncestor())
				.addWindowFocusListener((WindowFocusListener) handler);
	}

	private void initCollisionSelect()
	{
		JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEADING, 10, 10));
		panel.setBorder(BorderFactory.createTitledBorder("Collisions"));
		panel.add(new CollisionSelect());
		panel.add(new JButton("Auto-map"));
		add(panel, BorderLayout.CENTER);
	}

	private void initOptions()
	{
		JPanel panel = new JPanel();
		panel.setBorder(BorderFactory.createTitledBorder("Options"));
		panel.add(new JButton("Placeholder"));
		add(panel, BorderLayout.SOUTH);
	}

	private class CollisionSelect extends JButton
	{
		public CollisionSelect()
		{
			super("Line/Rectangle");
			addActionListener((ActionListener) handler);
		}
	}
}
